<template>
	<view class="main-container">
		<!--导航栏-->
		<orderTabBar :tabList="tabList" @clickTabBar="clickTabBar" class="tab-bar" :show-line="true" />
		<!--订单列表-->
		<scroll-view class="policy_list" scroll-y="true" :style="'height:87%'" enable-flex @scrolltolower="scrollToLower()" @scrolltoupper="updateOrderInfo()">
			<view class="policy_item" v-for="(item, index) in orderList" :key="index" @click="policyDetail(orderList[index])">
				<view style="width: 100%" class="item">
					<view class="policy_title">{{ item.subject||item.laboratoryname||item.kindName||item.post }}</view>
					<view class="item_right">
						<view class="right_item" v-if="currentIndex==0">
							产业领域：
							<text>{{item.industryName}}</text>
						</view>
						<view class="right_item" v-else-if="currentIndex==1">
							仪器型号：
							<text>{{item.model}}</text>
						</view>
						<view class="right_item" v-else-if="currentIndex==2">
							贷款额度：
							<text>{{item.quota}}</text>
							万
						</view>
						<view class="right_item" v-else-if="currentIndex==3">
							行业领域：
							<text>{{item.industryName}}</text>
						</view>
						<view class="right_item" v-if="currentIndex==0">
							合作方式：
							<text>{{item.hzfsName}}</text>
						</view>
						<view class="right_item" v-else-if="currentIndex==1">
							仪器分类：
							<text>{{item.classificationName}}</text>
						</view>
						<view class="right_item" v-else-if="currentIndex==2">
							所属行业：
							<text>{{item.industryName}}</text>
						</view>
						<view class="right_item" v-else-if="currentIndex==3">
							工作经验：
							<text>{{item.workYearName}}</text>
						</view>
					</view>
					<!-- <view style="width: 40%; float:left">
						<image style="height:150rpx;width: 260rpx; margin-top: 20rpx; margin-right: 20rpx; border-radius: 5rpx; float: left;" :src="item.coverImage"></image>
					</view> -->
					<!-- <view class="devideline"></view> -->
				</view>
				<!-- <view style="width: 100%;">
					<view>
						<view class="policy_title">{{item.insBasicName}}</view> 
						<text class="publicTime" style="float: right;">状态：{{getStatus(item.status)}}</text>
					</view>
					<view v-if="item.subscribeTime">
						<text class="publicTime">预约时间：{{item.subscribeTime}}</text>
					</view>
					<text class="publicTime" style="float: right;">服务类型：{{getType(item.serviceType)}}</text> -->
				<!-- 	<view class="devideline"></view> -->
				<!-- </view> -->
			</view>

			<view class="no-data" v-if="orderList.length == 0" @click="getOrderList()">
				<image src="https://file.genepre.com/wechat/nomsg5_new.png" mode="aspectFit" class="no-data-img"></image>
				{{ noData }}
			</view>
		</scroll-view>
	</view>
</template>

<script>
import env from '@/utils/env';
import * as dict from '@/api/system/dict/data.js';
import orderTabBar from '@/wxcomponents/tab_bar.vue';
import * as need from '@/api/personCenter/NEED.js';
import * as codeList from '@/utils/code.js';
import {findbyparentid} from '@/api/system/instype'

export default {
	components: {
		orderTabBar
	},
	data() {
		return {
			showPage: false,
			// 订单列表tab项
			tabList: [
				{
					status: '0',
					title: '成果需求'
				},
				{
					status: '1',
					title: '仪器需求'
				},
				{
					status: '2',
					title: '金融需求'
				},
				{
					status: '3',
					title: '人才需求'
				}
			],
			// 当前选择tab项
			currentIndex: 0,
			// 当前查询状态
			currentStatus: '',
			// 订单列表高度
			orderHeight: 0,
			// 是否还有更多数据
			noMoreData: {},
			// 订单列表
			orderList: [],
			// 页码数组
			query: {
				pageNum: 1,
				// 每页请求数
				pageSize: 10,
				memberId: ''
			},
			yqQuery: {
				pageNum: 1,
				// 每页请求数
				pageSize: 10,
				memberId: ''
			},
			jrQuery: {
				pageNum: 1,
				// 每页请求数
				pageSize: 10,
				memberId: ''
			},
			rcQuery: {
				pageNum: 1,
				// 每页请求数
				pageSize: 10,
				memberId: ''
			},
			policylevel: '',
			searchValue: '',
			noData: '加载中',
			total: 0,
			codeList: [],
			stayusList: [],
			// 产业领域
			chanyeList:[],
			// 合作方式
			hzfsData:[],
			// 仪器分类
			instypeList:[],
			// 企业类型
			typeList:[],
			// 所属行业
			indList:[],
			// 工作经验
			expList:[],
		};
	},
	onShow() {
		let _this = this;
		// const query = uni.createSelectorQuery().in(this);
		// query.select('.tab-bar').boundingClientRect(data => {
		//   _this.tabHeight = data.height
		//   _this.orderHeight = _this.windowHeight-5
		// }).exec();
		this.getUser();
		uni.showLoading({
			title: '加载中。。。'
		});
		this.getDictData();
		this.getOrderList();
	},
	mounted() {},
	methods: {
		getUser() {
			var mystorage = uni.getStorageSync('userInfo') || [];
			if (mystorage.login_user == null) {
				uni.navigateTo({
					url: '/subpages/pages/register/login_province'
				});
				uni.hideLoading();
				this.noData = '请先点击此处登录';
			} else {
				this.userInfo = mystorage.login_user.member;
				// this.query.userId = this.userInfo.id
				this.query.memberId = mystorage.login_user.member.id;
				this.yqQuery.memberId = mystorage.login_user.member.id;
				this.jrQuery.memberId = mystorage.login_user.member.id;
				this.rcQuery.memberId = mystorage.login_user.member.id;
			}
		},
		getDictData() {
			dict.getDicts('subscribe_type').then((res) => {
				this.statusList = res.data;
			});
			dict.getDicts('cms_industry_type').then((response) => {
				this.chanyeList = response.data;
			});
			dict.getDicts("ent_com_type").then((response) => {
			  this.typeList = response.data;
			});
			dict.getDicts("wanted_industry").then((response) => {
			  this.indList = response.data;
			});
			dict.getDicts('tzfs').then((response) => {
				this.hzfsData = response.data;
			});
			findbyparentid(0).then(response => {
			  this.instypeList = response.data;
			});
			dict.getDicts("wanted_exp").then((response) => {
			  this.expList = response.data;
			});
		},
		// tab切换
		clickTabBar(index, status) {
			this.currentIndex = index;
			console.log(this.currentIndex,typeof this.currentIndex);
			this.currentStatus = status;
			this.orderList = [];
			this.getOrderList();
		},
		// 加载订单列表
		getOrderList() {
			uni.showLoading({
				title: '加载中。。。'
			});
			this.noData = '加载中。。。';

			if (this.currentIndex == '0') {
				console.log('0000');
				need.CGNEED(this.query).then((res) => {
					if ((res.errMsg = 'request:fail')) {
						this.noData = '暂无数据，点击重试';
					}
					res.rows.forEach((v) => {
						if (v.coverImage != null) {
							v.coverImage = `${env.imgUrl}` + v.coverImage;
						}
						if(v.industry){
							v.industryName = this.chanyeList.find(item=>item.dictValue===v.industry).dictLabel
						}
						if(v.hzfs){
							v.hzfsName = this.hzfsData.find(item=>item.dictValue===v.hzfs).dictLabel
						}
						this.orderList.push(v);
					});
					this.total = res.total;
					uni.hideLoading({});
					if (this.orderList.length == 0) {
						this.noData = '暂无预约数据';
					}
				});
			} else if (this.currentIndex == '1') {
				console.log('1111');
				need.YQNEED(this.yqquery).then((res) => {
					if ((res.errMsg = 'request:fail')) {
						this.noData = '暂无数据，点击重试';
					}
					res.rows.forEach((v) => {
						if (v.coverImage != null) {
							v.coverImage = `${env.imgUrl}` + v.coverImage;
						}
						if(v.classification){
							console.log(v.classification);
							console.log(this.instypeList);
							v.classificationName = this.instypeList.find(item=>item.code===v.classification).name
						}
						this.orderList.push(v);
					});
					this.total = res.total;
					uni.hideLoading({});
					if (this.orderList.length == 0) {
						this.noData = '暂无预约数据';
					}
				});
			} else if (this.currentIndex == '2') {
				console.log('2222');
				need.JRNEED(this.jrQuery).then((res) => {
					if ((res.errMsg = 'request:fail')) {
						this.noData = '暂无数据，点击重试';
					}
					res.rows.forEach((v) => {
						if (v.coverImage != null) {
							v.coverImage = `${env.imgUrl}` + v.coverImage;
						}
						v.kindName = this.typeList.find(item=>item.dictValue===v.kind).dictLabel
						v.industryName = this.indList.find(item=>item.dictValue===v.industry).dictLabel
						this.orderList.push(v);
					});
					this.total = res.total;
					uni.hideLoading({});
					if (this.orderList.length == 0) {
						this.noData = '暂无预约数据';
					}
				});
			} else {
				console.log('3333');
				need.RCNEED(this.rcQuery).then((res) => {
					if ((res.errMsg = 'request:fail')) {
						this.noData = '暂无数据，点击重试';
					}
					res.rows.forEach((v) => {
						if (v.coverImage != null) {
							v.coverImage = `${env.imgUrl}` + v.coverImage;
						}
						v.industryName = this.indList.find(item=>item.dictValue===v.industry).dictLabel
						v.workYearName = this.expList.find(item=>item.dictValue===v.workYear).dictLabel
						this.orderList.push(v);
					});
					this.total = res.total;
					uni.hideLoading({});
					if (this.orderList.length == 0) {
						this.noData = '暂无预约数据';
					}
				});
			}
		},
		// 更新order
		updateOrderInfo(index) {
			// let _this = this
			// this.query.pageNum = 1
			// this.orderList = []
			// _this.getOrderList()
		},
		// 滑到底部 加载更多
		scrollToLower() {
			if (this.orderList.length < this.total) {
				if (this.currentIndex == '0') {
					this.query.pageNum = this.query.pageNum + 1;
				} else if (this.currentIndex == '1') {
					this.yqQuery.pageNum = this.yqQuery.pageNum + 1;
				} else if (this.currentIndex == '2') {
					this.jrQuery.pageNum = this.jrQuery.pageNum + 1;
				} else if (this.currentIndex == '3') {
					this.rcQuery.pageNum = this.rcQuery.pageNum + 1;
				}

				this.getOrderList();
			} else {
				uni.showToast({
					icon: 'none',
					title: '没有更多数据'
				});
			}
		},
		policyDetail(item) {
			// uni.navigateTo({
			// 	url:'/subpages/pages/detail/ask_detail?id='+item.id,
			// 	// url:'/pages/detail/policy_detail?id='+ item.id,
			// })
		},
		searchPolicy() {
			var data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				searchvalue: this.searchValue,
				code: 'KJZC'
			};
			article.getArticleByKeyword(data).then((res) => {
				console.log(res);
				this.orderList = res.rows;
			});
		},
		getType(type) {
			var serviceType = '';
			this.codeList.forEach((v) => {
				if (v.dictValue == type) {
					serviceType = v.dictLabel;
				}
			});
			return serviceType;
		},
		getStatus(type) {
			var serviceType = '';
			this.statusList.forEach((v) => {
				if (v.dictValue == type) {
					serviceType = v.dictLabel;
				}
			});
			return serviceType;
		}
	},
	computed: {}
};
</script>

<style lang="scss">
.main-container {
	width: 100vw;
	height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
	background-color: #e6e6e6;
}

.main-container .tab-bar {
	width: 100%;
}

.main-container .order-lists {
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	align-items: center;
}

.head {
	display: flex;
	width: 93vw;
	margin: 20rpx auto;
	height: 70rpx;
	border-radius: 30rpx;
	background-color: #fff;
	text-align: center;
}

.search_view {
	margin: 0 auto;
}

.search {
	height: 40rpx;
	padding-top: 15rpx;
	font-size: 25rpx;
	float: left;
}

.no-data {
	width: 100%;
	height: 300rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	font-size: 32rpx;
	margin-top: 100rpx;
}

.no-data .no-data-img {
	width: 300rpx;
	height: 268rpx;
}

.policy_list {
	width: 100%;
	margin: 20rpx 35rpx;
	height: fit-content;
}

.policy_item {
	height: 140rpx;
	background-color: #fff;
	margin-top: 15rpx;
	padding: 25rpx;
	.item{
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.item_right{
			font-size: 28rpx;
			text-align: right;
			flex: 1;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			.right_item{
				color: #333;
				text{
					color: #000;
					font-weight: 700;
				}
			}
		}
	}
}

.policy_title {
	display: -webkit-box;
	width: 50%;
	font-size: 30rpx;
	font-weight: 700;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	-webkit-box-orient: vertical; /*排列方式*/
	-webkit-line-clamp: 1; /*显示文本行数(这里控制多少行隐藏)*/
}

.publicTime {
	float: left;
	font-size: 26rpx;
	color: #a1a1a1;
	margin-top: 30rpx;
}

.devideline {
	float: left;
	height: 0.3rpx;
	width: 100%;
	background-color: #eeeeee;
	margin-top: 15rpx;
	margin-bottom: 15rpx;
}
</style>
